import time
from zhoukao3_0929.po.Base.Base import Base
from selenium.webdriver.common.by import By
class Page3(Base):
    dy1_loc=(By.XPATH,'/html/body/div[4]/a[2]')
    def dy1(self):
        return self.text(self.dy1_loc)
    # 点击商品
    sp_loc=(By.XPATH,'//img[@src="/uploads/images/20210629/da986e0513db8d7c38daf94cd76db3b7.jpg"]')
    def sp(self):
        self.click(self.sp_loc)

    # 断言，电饭煲家用智能定时预约新款多功能蒸饭蛋糕锅2-3-4-5升6人
    dy2_loc = (By.XPATH, '/html/body/div[4]/a[4]')
    def dy2(self):
        return self.text(self.dy2_loc)

    # 点击加入购物车
    gwc_loc=(By.ID,'add-cart')
    def gwc(self):
        self.click(self.gwc_loc)

#     查看购物车
    ckgwc_loc=(By.XPATH,'/html/body/div[3]/div[3]/div[2]/a')
    def ckgwc(self):
        self.click(self.ckgwc_loc)

#     断言我的购物车
    mygwc_loc=(By.XPATH,'/html/body/div[4]/div[1]/a[2]')
    def mygwc(self):
        return self.text(self.mygwc_loc)

#     勾选商品
    gxsp_loc=(By.XPATH,'//*[@id="cart-box"]/div[1]/table/tbody/tr[3]/td[1]/input')
    def gxsp(self):
        self.click(self.gxsp_loc)

#   立即结算
    js_loc=(By.XPATH,'//*[@id="cartForm"]/div[2]/div/a[2]')
    def js(self):
        self.click(self.js_loc)

#     断言确认订单
    dy3_loc=(By.XPATH,'/html/body/div[4]/div[1]/a[2]')
    def dy3(self):
        return self.text(self.dy3_loc)

#     勾选地址
    dz_loc=(By.XPATH,'/html/body/div[4]/form/div[1]/div[2]/div[14]/label/input')
    def dz(self):
        self.click(self.dz_loc)

#     点击下一步
    xyb_loc=(By.XPATH,'//*[@id="order-button"]')
    def xyb(self):
        self.click(self.xyb_loc)

#   断言订单完成
#     dy4_loc=(By.XPATH,'/html/body/div[4]/div[1]/a[2]')
#     def dy4(self):
#        return self.text(self.dy4_loc)

#   断言：您的订单支付成功
    dy5_loc=(By.XPATH,'/html/body/div[4]/div[3]/span')
    def dy5(self):
       return self.text(self.dy5_loc)

#   点击查看订单
    ckdd_loc=(By.XPATH,'/html/body/div[4]/div[3]/p/a')
    def ckdd(self):
        self.click(self.ckdd_loc)

#   断言编号
    dy6_loc=(By.XPATH,'/html/body/div[5]/div[2]/div/div[2]/table[2]/tbody/tr[2]/td[2]')
    def dy6(self):
        return self.text(self.dy6_loc)

#   断言支付状态
    dy7_loc=(By.XPATH,'/html/body/div[5]/div[2]/div/div[2]/table[2]/tbody/tr[4]/td[2]')
    def dy7(self):
        return self.text(self.dy7_loc)

#   断言订单状态
    dy8_loc=(By.XPATH,'/html/body/div[5]/div[2]/div/div[2]/table[2]/tbody/tr[5]/td[2]')
    def dy8(self):
       return self.text(self.dy8_loc)

    def test_spxiadan(self):
#         强制等待：给他10秒，他只有等过了10后才执行下一步
        time.sleep(2)
        assert "搜索结果" == self.dy1()
        print(self.dy1())
        time.sleep(2)
        self.sp()
        time.sleep(2)
        assert "电饭煲家用智能定时预约新款多功能蒸饭蛋糕锅2-3-4-5升6人" == self.dy2()
        print(self.dy2())
        self.gwc()
        self.ckgwc()
        assert "我的购物车" ==self.mygwc()
        print(self.mygwc())
        self.gxsp()
        self.js()
        assert "确认订单" == self.dy3()
        print(self.dy3())
        self.dz()
        self.xyb()
        # assert "订单完成" == self.dy4()
        # print(self.dy4())
        assert "您的订单支付成功" == self.dy5()
        print(self.dy5())
        self.ckdd()
        print(self.dy6())
        print(self.dy7())
        print(self.dy8())





